import {debounce} from "./utils";
import BackTop from "components/content/backtop/BackTop";

export const imgListenerMixin = {
  data() {
    return {
      imgListener: null,
      newRefresh: null
    }
  },
  mounted() {
    // 给防抖函数赋值一个新的函数
    this.newRefresh = debounce( this.$refs.scroll.refresh, 50);
    // 接收发射的事件总线, 并监听图片加载完成
    this.imgListener = () => {
      this.newRefresh();
    };
    this.$bus.$on('imageLoad', this.imgListener);
  },
};

export const backTopListenerMixin = {
  components: {
    BackTop
  },
  data() {
    return {
      isShowBackTop: false,
    }
  },
  methods: {
    backClick() {
      console.log("回到顶部");
      this.$refs.scroll.scrollTo(0, 0);
    },
    backTopListener(position) {
      // 判断BackTop是否显示
      this.isShowBackTop = (-position.y) > 1000;
    }
  }
};